/**
 * inforcreation.com co.Ltd
 * MichaelHuang
 * 2011-12-15
 */
package com.zchat.android;

import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.util.ArrayList;

import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

import com.zchat.android.app.BaseActivity;
import com.zchat.android.widget.ScrollLayout;
import com.zchat.android.widget.ScrollPageControlView;
import com.zchat.api.log.Logger;

/**
 * Help activity. Use to first use human.
 * @author MichaelHuang
 */
public class HelpActivity extends BaseActivity {
	private static final String TAG = "HelpActivity";
	private ScrollLayout scrollView;
	private ScrollPageControlView scrollViewControl;
	private ArrayList<Drawable> images = new ArrayList<Drawable>();
	
	/** 邮箱注册 */
	private Button sign;
	
	/** 登录  */
	private Button login;

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.help);
		
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void initComponents() {
		scrollView = (ScrollLayout) findViewById(R.id.helpScrollView);
		scrollViewControl = (ScrollPageControlView) findViewById(R.id.helpScrollControl);
		scrollViewControl.setActivity(this);
		
		sign = (Button) findViewById(R.id.sign);
		
		login = (Button) findViewById(R.id.login);
	}

	@Override
	protected void initDatas() {
		try {
			InputStream in = getResources().getAssets().open("help1.png");
			SoftReference<Drawable> drawable = new SoftReference<Drawable>(new BitmapDrawable(in));
			images.add(drawable.get());
			in.close();
			InputStream in2 = getResources().getAssets().open("help2.png");
			SoftReference<Drawable> drawable2 = new SoftReference<Drawable>(new BitmapDrawable(in2));
			images.add(drawable2.get());
			in.close();
			InputStream in3 = getResources().getAssets().open("help3.png");
			SoftReference<Drawable> drawable3 = new SoftReference<Drawable>(new BitmapDrawable(in3));
			images.add(drawable3.get());
			in.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		for(Drawable imageRes : images) {
			ImageView image = new ImageView(this);
			image.setBackgroundDrawable(imageRes);
			scrollView.addView(image);
		}
		
		scrollViewControl.setCount(scrollView.getChildCount());
		scrollViewControl.generatePageControl(0);
		scrollView.setSnapToScreenCallback(scrollViewControl);
	}

	@Override
	protected void setComponentListeners() {
		sign.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
			}
		});
		
		login.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				 Intent intent = 
						 new Intent(HelpActivity.this, LoginActivity.class);
				 startActivity(intent);
			}
		});
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		switch (keyCode) {
		case KeyEvent.KEYCODE_BACK:
			finish();
			System.exit(0);
		default:
			break;
		}
		return true;
	}
	
	@Override
	public String toString() {
		return TAG;
	}
		
}
